package team.hyznrj.studentsys.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import org.springframework.util.StringUtils;
public class QualityStudent extends StudentBasicMessage {
	/** 链表 */
	List<QualityAchievementNode> value=new ArrayList<>();
	/**分值存储*/
	Map<String,Float> typesValue=new HashMap<>();
	public final static float ZERO=0.0f;
	/**
	 * @param key 格式:XXXX分#年份#学期#主题
	 * @param obj 操行分对象
	 */
	public void put(String key,QualityAchievement obj) {
		QualityAchievementNode node = new QualityAchievementNode(key,obj);
		value.add(node);
		/**计算分值*/
		String tmp=key.split("#")[0];
		if(!StringUtils.isEmpty(tmp)){
			float val = typesValue.getOrDefault(tmp,  ZERO)+node.getValue();
			typesValue.put(tmp, val);
		}
	}
	/**获取操行分的值*/
	public float getQualityValue(String key){
		return typesValue.getOrDefault(key,  ZERO);
	}
	/**
	 * 获取学生操行分信息(会根据类型年份先排序再RETURN)
	 * @return
	 */
	public List<QualityAchievementNode> getValue() {
		for (int i = 0; i < value.size(); i++) {
			QualityAchievementNode tmp = value.get(i);
			String str = tmp.getKey();
			int swap = -1;
			for (int j = i + 1; j < value.size(); j++) {
				String tmpStr = value.get(j).getKey();
				if (str.compareTo(tmpStr) > 0) {
					swap = j;
				}
			}
			if (swap != -1) {
				value.set(i, value.get(swap));
				value.set(swap, tmp);
			}
		}
		return value;
	}
	/**获取学生操行分个数*/
	public int getLength() {
		return value.size();
	}
	
}

